﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Text;

public partial class Admin_CustomerActive : System.Web.UI.Page
{
    ShopLaptopConnection connect;
    SqlConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        connect = new ShopLaptopConnection();
        conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ShopLaptopConnectionString"].ConnectionString);
        if (!IsPostBack)
        {
            if (Session["Admin"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            DisplayCusStatus1();

        }
    }

    protected void DisplayCusStatus1()
    {
        grCustomerActive.DataSource = "";
        grCustomerActive.DataBind();
        SqlDataAdapter da = new SqlDataAdapter("Select * From Customer Where CusStatus=1", conn);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            grCustomerActive.DataSource = dt;
            grCustomerActive.DataBind();
        }
    }


    protected void grCustomerActive_SelectedIndexChanged(object sender, EventArgs e)
    {
        int cusID = Convert.ToInt32(grCustomerActive.Rows[grCustomerActive.SelectedIndex].Cells[0].Text);
        //Response.Write(cusID.ToString());
        int check = 0;
        check = connect.SetCusStatus0(cusID);
        if (check > 0)
        {
            DisplayCusStatus1();

        }
    }
    protected void grCustomerDisable_SelectedIndexChanged(object sender, EventArgs e)
    {
        int cusID = Convert.ToInt32(grCustomerActive.Rows[grCustomerActive.SelectedIndex].Cells[0].Text);
        //Response.Write(cusID.ToString());
        int check = 0;
        check = connect.SetCusStatus1(cusID);
        if (check > 0)
        {
            DisplayCusStatus1();

        }
    }
    protected void grCustomerActive_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {

    }

    private void ShowPopUpMsg(string msg)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("alert('");
        sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
        sb.Append("');");
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true);
    }
    protected void grCustomerActive_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int cusID = Convert.ToInt32(grCustomerActive.Rows[e.RowIndex].Cells[0].Text);
        int check = 0;
        check = connect.ResetCusPass(cusID);
        if (check > 0)
        {
            ShowPopUpMsg("Reset successfuly!");
        }
    }
}

